# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI=2

inherit eutils

DESCRIPTION="Manages the proof cluster"
HOMEPAGE="http://www.gentoo.org/"
SRC_URI="http://alicepc100.jinr.ru/gentoo-files/xproofd-scripts-${PVR}.tar.bz2"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~x86 ~amd64"
IUSE=""
CDEPEND="sci-physics/root-svn"

DEPEND="${CDEPEND}"

pkg_preinst() {
    enewuser xproofd -1 -1 -1 root
}

src_install() {
  insinto /etc/xproofd
  newins "${WORKDIR}/${P}/xproofd/prf-main.cf" prf-main.cf || die
  newins "${WORKDIR}/${P}/xproofd/groups.cf.alice" groups.cf.alice || die
  newins "${WORKDIR}/${P}/xproofd/proof.conf" proof.conf || die
  newins "${WORKDIR}/${P}/xproofd/XrdSecgsiGMAPFunLDAP.cf" XrdSecgsiGMAPFunLDAP.cf || die

  insinto /var/log/
  newins "${WORKDIR}/${P}/log/xproofd.log" xproofd.log || die

  dobin "${WORKDIR}/${P}/bin/xproofd_init" || die

  newinitd "${WORKDIR}/${P}/init.d/xproofd" xproofd
  newconfd "${WORKDIR}/${P}/conf.d/xproofd" xproofd
}

pkg_postinst()
{
  chown xproofd "${ROOT}"var/log/xproofd.log
}

pkg_config() {
    if [ ! -d "${ROOT}"var/spool/xproofd/ ] ; then
        einfo "Press ENTER to create the pool directory structure and set proper"
        einfo "permissions on it, or Control-C to abort now..."
        read
        "${ROOT}"/usr/bin/xproofd_init
    else
        einfo "Hmm, it appears as though you already have the pool"
        einfo "in place.  If you are having problems trying"
        einfo "to start xproofd, perhaps you need to remove ${ROOT}var/spool/xproofd/"
        einfo "first."
    fi
}